package com.four.peoplemanage.cards.service;

import com.four.peoplemanage.cards.dao.CardsDao;
import com.four.peoplemanage.cards.entity.Cards;
import com.four.peoplemanage.common.bean.Page;
import com.four.peoplemanage.gift.entity.Gift;
import com.four.peoplemanage.holiday.entity.Holiday;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CardsService {
    @Autowired
    private CardsDao cardsDao;
    //查看门卡
    public Page<Cards> getOnrePage(int pageNum, int pageSize
    ){
        //计算起始位置
        int start=(pageNum-1)*pageSize;
        //获取分页的数据
        List<Cards> list=cardsDao.canCards(start,pageSize);
        //获取总条目数
        int total=cardsDao.countCards();
        //计算总页数
        int pages =(int) (total % pageSize == 0 ? total / pageSize : total / pageSize + 1);
        //创建分页对象
        Page<Cards> page=new Page<>();
        page.setRecords(list);
        page.setTotal(total);
        page.setPages(pages);
        page.setCurrent(pageNum);
        page.setSize(pageSize);
        return page;
    }
    //添加
    public boolean insert(Cards cards){
        if (cards == null){
            return false;
        }
        return cardsDao.addCard(cards)>0;
    }
}
